using UnityEngine;

public class UIOptionsPanel : MonoBehaviour, IBackAction
{
	public UIDoubleStateButton soundButton;

	public UIDoubleStateButton musicButton;

	private bool hiding;

	private void Start()
	{
		if (soundButton != null)
		{
			soundButton.SetState(UserPreferences.instance.playerData.sound);
		}
		if (musicButton != null)
		{
			musicButton.SetState(UserPreferences.instance.playerData.music);
		}
		Globals.instance.backManager.RegisterObject(this);
	}

	public void OnFacebookButtonPressed()
	{
		AudioController.instance.Play("button");
		if (checkPackageAppIsPresent("com.facebook.katana"))
		{
			//Application.OpenURL(Globals.instance.fbFanpageApplication);
		}
		else
		{
			//Application.OpenURL(Globals.instance.fbFanpageLink);
		}
	}

	public void OnAchievementsButtonPressed()
	{
	}

	public void OnPrivacyButtonPressed()
	{
		AudioController.instance.Play("button");
		GameObject original = Resources.Load<GameObject>("RODO_Privacy_Menu");
		GameObject gameObject = UnityEngine.Object.Instantiate(original);
	}

	public void OnMusicButtonPressed(bool state)
	{
		AudioController.instance.Play("button");
		UserPreferences.instance.playerData.music = state;
		UserPreferences.instance.Save();
		if (state)
		{
			AudioController.instance.PlayBackground("msc_background");
		}
		else
		{
			AudioController.instance.PauseBackground();
		}
	}

	public void OnSoundButtonPressed(bool state)
	{
		AudioController.instance.Play("button");
		UserPreferences.instance.playerData.sound = state;
		UserPreferences.instance.Save();
	}

	public void OnBackAction()
	{
		if (!hiding)
		{
			AudioController.instance.Play("button");
			hiding = true;
			GetComponent<Animator>().SetTrigger("Hide");
		}
	}

	public void OnEndHide()
	{
		UnityEngine.Object.Destroy(base.gameObject);
	}

	public void OnEndShow()
	{
	}

	private bool checkPackageAppIsPresent(string package)
	{
		AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
		AndroidJavaObject @static = androidJavaClass.GetStatic<AndroidJavaObject>("currentActivity");
		AndroidJavaObject androidJavaObject = @static.Call<AndroidJavaObject>("getPackageManager", new object[0]);
		AndroidJavaObject androidJavaObject2 = androidJavaObject.Call<AndroidJavaObject>("getInstalledPackages", new object[1]
		{
			0
		});
		int num = androidJavaObject2.Call<int>("size", new object[0]);
		for (int i = 0; i < num; i++)
		{
			AndroidJavaObject androidJavaObject3 = androidJavaObject2.Call<AndroidJavaObject>("get", new object[1]
			{
				i
			});
			string text = androidJavaObject3.Get<string>("packageName");
			if (text.CompareTo(package) == 0)
			{
				return true;
			}
		}
		return false;
	}
}
